package DailyPractice.Day3;

/**
 * @author lumin
 * @date 2022/04/20 12:09
 **/
public class Num2 {
    public int MoreThanHalfNum_Solution(int[] array) {
        int count = 0;
        int midNum = array[0];
        for (int i = 0; i < array.length; i++) {
            if (count == 0) {
                midNum = array[i];
                count = 1;
            } else if (midNum == array[i]) {
                count++;
            } else {
                count--;
            }
        }
        return midNum;
    }
}